MkProgressBar
Node to display a CSS-based progress bar.
Examples
Example: Regular
Note
Jinja
{{ 60 | MkProgressBar }}
Note
Python
MkProgressBar(60)
Rendered
██████░░░░ 60%
Markdown
`██████░░░░` 60%
Html
<p><code>██████░░░░</code> 60%</p>
GitHub
`██████░░░░` 60%
Example: Style thin
Note
Jinja
{{ 60 | MkProgressBar(style="thin") }}
Note
Python
MkProgressBar(60, style='thin')
Rendered
██████░░░░ 60%
Markdown
`██████░░░░` 60%
Html
<p><code>██████░░░░</code> 60%</p>
GitHub
`██████░░░░` 60%
Example: Style candystripe
Note
Jinja
{{ 70 | MkProgressBar(style="candystripe") }}
Note
Python
MkProgressBar(70, style='candystripe')
Rendered
███████░░░ 70%
Markdown
`███████░░░` 70%
Html
<p><code>███████░░░</code> 70%</p>
GitHub
`███████░░░` 70%
Example: Style candystripe_animated
Note
Jinja
{{ 80 | MkProgressBar(style="candystripe_animated") }}
Note
Python
MkProgressBar(80, style='candystripe_animated')
Rendered
████████░░ 80%
Markdown
`████████░░` 80%
Html
<p><code>████████░░</code> 80%</p>
GitHub
`████████░░` 80%
Base classes
| Name | Children | Inherits |
|---|---|---|
| MkNode mknodes.basenodes.mknode Base class for everything which can be expressed as Markup. |
⋔ Inheritance diagram
graph TD
492688635["mkprogressbar.MkProgressBar"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
1359323199 --> 492688635
2751680898 --> 1359323199
NodeFile
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkprogressbar/metadata.toml
[metadata]
icon = "fa6-solid:bars-progress"
name = "MkProgressBar"
[[resources.css]]
filename = "progressbar.css"
[requirements.extension."pymdownx.progressbar"]
[examples.regular]
title = "Regular"
jinja = """
{{ 60 | MkProgressBar }}
"""
[examples.style_thin]
title = "Style thin"
jinja = """
{{ 60 | MkProgressBar(style="thin") }}
"""
[examples.style_candystripe]
title = "Style candystripe"
jinja = """
{{ 70 | MkProgressBar(style="candystripe") }}
"""
[examples.style_candystripe_animated]
title = "Style candystripe_animated"
jinja = """
{{ 80 | MkProgressBar(style="candystripe_animated") }}
"""
[output.markdown]
template = """
[={{ node.percentage }}% "{{ node.label }}"]
"""
[output.html5]
template = """
<label for="progress_bar">{{ node.label }}:</label>
<progress id="progress_bar" max="100" value="{{ node.percentage }}">{{ node.percentage }}%</progress>
"""
Code
mknodes.basenodes.mkprogressbar.MkProgressBar
class MkProgressBar(mknode.MkNode):
"""Node to display a CSS-based progress bar."""
REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.progressbar")]
ICON = "fontawesome/solid/bars-progress"
CSS = [resources.CSSFile("progressbar.css")]
ATTR_LIST_SEPARATOR = ""
def __init__(
self,
percentage: int,
*,
label: str | Literal[True] | None = True,
style: Literal["thin", "candystripe", "candystripe_animated"] | None = None,
**kwargs: Any,
) -> None:
"""Constructor.
Args:
percentage: Percentage value for the progress bar
label: Label to display on top of progress bar
style: Progress bar style
kwargs: Keyword arguments passed to parent
"""
super().__init__(**kwargs)
self._label = label
self.percentage = percentage
self.style = style
match self.style:
case "thin":
self.add_css_class("thin")
case "candystripe":
self.add_css_class("candystripe")
case "candystripe_animated":
self.add_css_class("candystripe")
self.add_css_class("candystripe-animate")
case None:
pass
@property
def label(self) -> str:
match self._label:
case str():
return self._label.format(percentage=self.percentage)
case True:
return f"{self.percentage}%"
case _:
return ""
def to_md_unprocessed(self) -> str:
return rf'[={self.percentage}% "{self.label}"]'
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
def create_section_for_nodes(
nav: mk.MkNav,
klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
for kls in klasses:
tpl = "classpage_custom.jinja"
page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
nav += page
if kls.STATUS:
page.metadata.status = kls.STATUS
elif kls.JS_FILES:
page.metadata.status = "js"
elif kls.CSS:
page.metadata.status = "css"
page.created_by = create_section_for_nodes
link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
table.add_row((link, kls.__doc__, extensions))
return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7d707a397060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: fontawesome/solid/bars-progress
status: css
title: MkProgressBar